package br.com.absolutech.study.chapter7.pag320;

import java.util.HashMap;
import java.util.Map;

class Dog {

	public String name;

	public Dog(String n) {
		name = n;
	}

	public boolean equals(Object o) {
		if ((o instanceof Dog) && ((Dog) o).name == name) {
			return true;
		} else {
			return false;
		}
	}

	public int hashCode() {
		return name.length();
	}
}

class Cat {
}

enum Pets {
	DOG, CAT, HORSE
};

public class MapTest {

	public static void main(String[] args) {

		Map<Object, Object> m = new HashMap<Object, Object>();

		m.put("k1", new Dog("aiko")); //adiciona alguns pares de chave/valor
		m.put("k2", Pets.DOG);
		m.put(Pets.CAT, "CAT key");
		Dog d1 = new Dog("clover"); //vamos manter esta referencia
		m.put(d1, "Dog key");
		m.put(new Cat(), "Cat key");

		System.out.println(m.get("k1"));
		String k2 = "k2";
		System.out.println(m.get(k2));
		Pets p = Pets.CAT;
		System.out.println(m.get(p));
		System.out.println(m.get(d1));
		System.out.println(m.get(new Cat()));
		System.out.println(m.size());


		d1.name = "magnolia";
		System.out.println(m.get(d1));
		
		d1.name = "clover";
		System.out.println(m.get(new Dog("clover")));
		
		d1.name = "arthur";
		System.out.println(m.get(new Dog("clover")));


	}

}
